package com.uni.exp4.pojo;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * --------------MyBatisFastUse-------------
 *
 * @Author Unirithe  - Mr.Chao
 * - CSDN:
 * https://blog.csdn.net/Unirithe
 * - GitHub:
 * https://github.com/unirithe
 * @create 2022/1/18 9:58
 * ------------------------------------------
 */

@Data
@NoArgsConstructor
public class TextPaper implements Paper{
    private int charPerLine = 15;   // 每行字符数
    private int linePerPage = 6;    // 每页行数
    private String content = "";    // 纸张内容
    private int posX = 0;           // 当前横向位置，[0, charPerLIne-1]
    private int posY = 0;           // 当前纵向位置，[0, linePerPage-1]
    private int posPage = 1;        // 当前页数
    @Override
    public void printChar(char c) {
        content += c;
        ++posX;
        // 换行
        if(posX == charPerLine){
            content += Paper.NEXT;
            posX = 0;
            ++ posY;
        }
        // 翻页
        if(posY == linePerPage){
            content += "===== 第 " + posPage + " 页 =====";
            content += Paper.NEXT +Paper.NEXT;
            posY = 0;
            ++posPage;
        }
    }

    @Override
    public String getContent() {
        String ret = this.content;
        // 补齐本页空行，并显示页码
        if(!(posX ==0 && posY == 0)){
            int count = linePerPage - posY;
            for (int i = 0; i < count; i++)
                ret += Paper.NEXT;
            ret += "====== 第 " + posPage +" 页 ======";
        }
        return ret;
    }
}
